|
|
|
|
|
|
|
);
// show the table
SELECT * FROM JobsTable;
// eof |
|
|
|
|
|
|
|
|
Enter this code into the SQL-Visual Basic editor, save the script as SQLVB04.SQV and execute it. You see a simple table that shows two fields. See Figure 13.12 for an example. |
|
|
|
|
|
|
|
|
Figure 13.12.
Defining the PRIMARY KEY CONSTRAINT. |
|
|
|
|
|
|
|
|
The SQL script in Listing 13.9 performs the same task, except it uses the CREATE INDEX keyword to define the primary key index. |
|
|
|
|
|
|
|
|
Listing 13.9. Using CREATE INDEX to define the PRIMARY KEY. |
|
|
|
|
|
|
|
|
//
// create index using CREATE INDEX keywords
//
// create database
dbMake sqlvb04.mdb;
// create table
CREATE TABLE JobsTable
(JobTitle TEXT(20),
JobDesc MEMO
);
// create index
CREATE INDEX PKJobTitle ON JobsTable(JobTitle) WITH PRIMARY;
// eof |
|
|
|
|
|
|
|
|
Although the code examples in Listing 13.8 and Listing 13.9 both perform the same task, the first code example (Listing 13.8) is the preferred method for creating primary key indexes. Listing 13.8 documents the creation of the index at the time the table is created. This is easier to understand and easier to maintain over time. It is possible to create primary key indexes using the CREATE INDEX statement, but this can lead to problems. If you attempt to use the CREATE INDEX_PRIMARY KEY statement on a table that already has a primary key index defined, |
|
|
|
|
|